<?php
declare (strict_types=1);

namespace app\common\model;

use think\facade\Cache;
use think\facade\Event;

class Activity extends Base
{
    protected $name = 'activity';

    public static function submit($param, $user): array
    {
        try {
            $info = parent::where(['id' => $param['id'], 'is_del' => 0, 'status' => 1])->find();
            if (empty($info)) {
                return ['code' => -1, 'msg' => '活动不存在或已下架'];
            }
//            $order = ActivityOrder::where(['a_id'=>$param['id'],'uid'=>$user->id])->find();
//            if($order)
//            {
//                return ['code' => -1, 'msg' => '不可重复购买'];
//            }
            if (!$info->price || $info->price <= 0) {
                return ['code' => -1, 'msg' => '活动价格错误'];
            }
            $all = [
                'aid' => $info->id,
                'name' => $param['name'],
                'phone' => $param['phone'],
                'address' => $param['address'],
            ];
            Cache::set('activityOrder_' . $user->id, json_encode($all));

            return ['code' => 4, 'msg' => 'success'];

        } catch (\Exception $e) {
            return ['code' => -1, 'msg' => $e->getMessage()];
        }
    }


}
